$(document).ready(function () {



    layui.use(function () {

        var layer = layui.layer;


        $('input[name="status"]').on('click', function () {
            curStatus = $(this).val();
            generateData()
        });

        $('#queryInput').click();


    });
})

var curStatus = '';

function generateData() {

    new AjaxChain()
        .setUrl('/work/task/list/lastest')
        .setData({
            status: curStatus
        })
        .then(data => {

            var temp;
            var td = [];
            var str = '';


            data.forEach(t => {
                temp = {};
                var e = t.seqNo + "、" + t.name;
                switch (t.type) {
                    case 1: temp = { t1: "年度工作", t2: "半年工作", t3: "季度工作", t4: "每月工作", t5: "每周工作", t6: "每日工作" }; break;
                    case 2: temp = { t1: "年度工作", t2: "半年工作", t3: "季度工作", t4: "每月工作", t5: "每周工作", t6: e }; break;
                    case 3: temp = { t1: "年度工作", t2: "半年工作", t3: "季度工作", t4: "每月工作", t5: e, t6: e }; break;
                    case 4: temp = { t1: "年度工作", t2: "半年工作", t3: "季度工作", t4: e, t5: e, t6: e }; break;
                    case 5: temp = { t1: "年度工作", t2: "半年工作", t3: e, t4: e, t5: e, t6: e }; break;
                    case 6: temp = { t1: "年度工作", t2: e, t3: e, t4: e, t5: e, t6: e }; break
                }
                temp.t7 = e, temp.t8 = t.manageTypeDesc, temp.t9 = t.content, temp.status = t.status, temp.id = t.id, temp.seqNo = t.seqNo, temp.type = t.type, temp.doneDesc = t.doneDesc, td.push(temp)
            });

            td.sort((a, b) => a.type - b.type);

            str = td.reduce((t, d, s) => {
                let a = 0 == s ? "table-tit" : "", l = 0 == s ? '<img src="../static/img/ti.png" alt="">' : "";
                return t + `<tr>
                            ${"年度工作" == d.t1 ? `<td class="${a}">${d.t1 + l}</td>` : `<td>${d.t1}</td>`}
                            ${"半年工作" == d.t2 ? `<td class="${a}">${d.t2 + l}</td>` : `<td>${d.t2}</td>`}
                            ${"季度工作" == d.t3 ? `<td class="${a}">${d.t3 + l}</td>` : `<td>${d.t3}</td>`}
                            ${"每月工作" == d.t4 ? `<td class="${a}">${d.t4 + l}</td>` : `<td>${d.t4}</td>`}
                            ${"每周工作" == d.t5 ? `<td class="${a}">${d.t5 + l}</td>` : `<td>${d.t5}</td>`}
                            ${"每日工作" == d.t6 ? `<td class="${a}">${d.t6 + l}</td>` : `<td>${d.t6}</td>`}
                            <td>${d.t7}</td>
                            <td>${d.t8}</td>
                            <td>${d.t9}</td>
                            <td>${2 == d.status ? ((d.doneDesc == "" || d.doneDesc == null) ? "已完成" : `<div data-tip="${d.doneDesc}" class="btn-tips">处理详情</div>`) : `<div onclick=handlePlan("${d.id}") style="width: auto;height: 0.28rem;" class="layui-btn"> 处理</div>`}</td>
                        </tr>
                `}, "");
            $('tbody').empty().append(str);
            mergeTableCells('#plan-table')



            // 鼠标移入提示
            var tipContent = null;
            $('.btn-tips').click(
                function () { // 鼠标移入时触发
                    tipContent = $(this).data('tip');
                    tipIndex = layer.tips(tipContent, this, {
                        tips: [2, '#2273a1'], // 提示方向和控制背景色
                        time: 0 // 不自动关闭
                    });
                },
            );

            $('.btn-tips').hover(
                function () { // 鼠标移入时触发
                },
                function () { // 鼠标移出时触发
                    layer.close(tipIndex); // 关闭提示层
                }
            );
        })
        .catch(err => {
            console.error('请求异常:', err);
        })
        .send();
}


function savePlan() {
    const width = document.documentElement.scrollWidth, height = $("#plan-table").height() + $(".main-title").height() + 60;
    html2canvas(
        document.body,
        {
            scrollX: 0,
            scrollY: 0,
            windowWidth: width,
            windowHeight: height,
            scale: 2,
            useCORS: !0
        }
    ).then(t => {
        let e = document.createElement("a");
        e.download = "消防站工作“一张图”.png", e.href = t.toDataURL("image/png"), e.click()
    });
}


